import ACCESS_ENUM from "@/access/accessEnum";
import AccessEnum from "@/access/accessEnum";
import accessEnum from "@/access/accessEnum";

/**
 * 检查权限 ： 判断当前登录用户是否有这个权限
 * @param loginUser  当前用户
 * @param needAccess  需要有的权限
 * @return boolean  有无权限
 */
const checkAccess = (loginUser: any, needAccess = ACCESS_ENUM.NOT_LOGIN) => {
  console.log(loginUser, needAccess, "hehe");
  const loginUserAccess = loginUser?.userRole ?? ACCESS_ENUM.NOT_LOGIN;

  if (needAccess === AccessEnum.NOT_LOGIN) {
    return true;
  }
  if (needAccess === AccessEnum.USER) {
    if (loginUserAccess === ACCESS_ENUM.NOT_LOGIN) {
      return false;
    }
  }

  if (needAccess === ACCESS_ENUM.ADMIN) {
    if (loginUserAccess !== ACCESS_ENUM.ADMIN) {
      return false;
    }
  }

  return true;
};

export default checkAccess;
